package com.example.springboot.entity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpInfo {
    public static void main(String[] args) {
        try {
            // 创建URL对象
            URL url = new URL("");

            // 创建HttpURLConnection对象
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // 设置请求方法为POST
            connection.setRequestMethod("POST");

            // 设置请求头
            connection.setRequestProperty("Content-Type", "application/json");

            // 允许写入请求内容
            connection.setDoOutput(true);

            // 构建请求体
            String requestBody = "{\"account\":\"90000007501\",\"graphId\":\"f72db590e4af4219804df0a0fa753d76\",\"graphCode\":\"4\",\"password\":\"5mm9853a3742a541c102289f59351694ec0e4tot\",\"loginflag\":\"loginPassword\",\"unifiedAccessReqDTO\":{\"loginType\":\"0\"}}";

            // 获取输出流
            OutputStream outputStream = connection.getOutputStream();
            outputStream.write(requestBody.getBytes());
            outputStream.flush();
            outputStream.close();

            // 获取响应码
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            // 读取响应内容
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            StringBuilder response = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();

            // 输出响应内容
            System.out.println("Response: " + response.toString());

            // 关闭连接
            connection.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
